class Admin::UsersController < AdminController
  def index
    @users = User.order("created_at DESC").page params[:page]
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new user_params
    if @user.save
      redirect_to admin_users_path, notice: "保存成功！"
    else
      redirect_to admin_users_path, notice: "保存失败！"
    end
  end

  def edit
    @user = User.find params[:id]
  end

  def update
    @user = User.find params[:id]
    if @user.update user_params
      redirect_to admin_users_path, notice: "更新成功！"
    else
      redirect_to admin_users_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @user = User.find params[:id]
    if @user.destroy
      redirect_to admin_users_path, notice: "删除成功."
    else
      redirect_to admin_users_path, notice: "删除失败."
    end
  end

  private

  def user_params
    params.require(:user).permit(:nickname, :phone, :password)
  end
end
